#include "comm.hpp"


int main()
{
    int fdin = open("mycopy.txt", O_CREAT | O_RDONLY, MODE);
    if(fdin < 0)
    {
        perror("serve.cc::mkfifo::main");
        return 1;
    }

    int fd = open(PATHNAME, O_CREAT | O_WRONLY, MODE);
    if(fd < 0)
    {
        perror("serve::open::main");
    }

    //缓冲区
    char buffer[SIZE] = {0};

    while(true)
    {
        buffer[0] = '\0';
        ssize_t s = read(fdin, buffer, sizeof(buffer));
        if(s > 0)
        {   
            buffer[s] = '\0';
            write(fd, buffer, sizeof(buffer));
            printf("copy success!!!\n");
        }
        else if(s == 0)
        {
            printf("client normal quit!!\n");
            break;
        }
        else
        {
            printf("client error quit!!\n");
            break;
        }
    }

    close(fdin);
    close(fd);
    return 0;
}